package models

import (
	"log"
	"quantization_trading/src/util"
	"strings"
)

type Account struct {
	Id int `gorm:"primaryKey"`
	AccountName string `json:"account_name"`//账号名
	Exchange string `json:"exchange"` //交易所
	ApiKey           string `json:"api_key"`
	SecretKey        string `json:"secret_key"`
	Passphrase    string `json:"passphrase"`
	UseStatus	bool `json:"use_status"`
}

func (Account)TableName() string {
	return "account"
}

func AddAccount(account *Account) int {
	var Accounts []Account
	db.Where("account_name = ?",strings.ToLower(account.AccountName)).Find(&Accounts)
	if len(Accounts) == 0{
		if err := db.Create(account).Error; err != nil {
			log.Fatal(err)
			return util.ADD_ERROR
		}
		return util.ADD_SUSSESS
	}else {
		return util.ADD_HAVE_DATA
	}

}

func DelAccount(Account *Account) int {
	db.Delete(Account)
	return util.DELETE_SUSSESS_ACCOUNT
}

func FindAllAccount() ([]Account, error) {
	var account_list []Account
	db.Find(&account_list)
	return account_list,nil
}